/*
 * Copyright (c) 2018, ZeeSec Technologies. All rights reserved.
 * ZeeSec PROPRIETARY/CONFIDENTIAL.
 */

package springtest.quartz;

import java.util.Date;

import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @author ZhiQiang Chen
 * @date 2018-10-08 10:03:35
 */

public class TestOneJopByManyTrigger {

    public static void main(String[] args) throws Exception {
        // 首先要实例化scheduler
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();
        // 获取job实例
        JobDataMap jobDataMap = new JobDataMap();
        jobDataMap.put("a", "我是一个触发器aa");
        JobDataMap jobDataMap2 = new JobDataMap();
        jobDataMap2.put("a", "我是第二个个触发器aa");
        JobDetail job = JobBuilder.newJob(TestJob.class).withIdentity("job1", "group1").usingJobData(jobDataMap)
                .build();
        JobDetail job2 = JobBuilder.newJob(TestJob.class).withIdentity("job2", "group1").usingJobData(jobDataMap2)
                .build();
        // TriggerBuilder<Trigger> newTrigger = TriggerBuilder.newTrigger();
        // 测试第一个触发器
        jobDataMap.put("a", "我是一个触发器");
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1").startAt(new Date())
                .usingJobData(jobDataMap).build();
        // 测试第二个触发器
        jobDataMap2.put("a", "我是第二个个触发器");
        Trigger trigger2 = TriggerBuilder.newTrigger().withIdentity("trigger2", "group1").startAt(new Date())
                .usingJobData(jobDataMap2).build();

        // 告诉quartz使用某个trigger执行某个job
        scheduler.scheduleJob(job, trigger);
        scheduler.scheduleJob(job2, trigger2);
        // 启动scheduler
        scheduler.start();
    }

}
